/**
 * Project Name:kany-project-blog-web
 * File Name:AuthenticationExceptionMapper.java
 * Package Name:me.kany.project.blog.resource.mapper
 * Date:2016年9月21日下午5:28:21
 * Copyright (c) 2016, Jason.Wang All Rights Reserved.
 */
package me.kany.project.blog.resource.mapper;

import javax.ws.rs.NotAuthorizedException;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.ext.ExceptionMapper;

import me.kany.project.blog.resource.model.GenericErrorMessage;


/**
 * ClassName:AuthenticationExceptionMapper<br/>
 * Function: 自定义返回的错误信息<br/>
 * Date:2016年9月21日下午5:28:21<br/>
 * 
 * @author Jason.Wang
 * @version 1.0
 * @since JDK1.7
 * @see
 */
public class AuthenticationExceptionMapper implements ExceptionMapper<NotAuthorizedException> {

	/* (non-Javadoc)
	 * @see javax.ws.rs.ext.ExceptionMapper#toResponse(java.lang.Throwable)
	 */
	@Override
	public Response toResponse(NotAuthorizedException exception) {
		GenericErrorMessage e = new GenericErrorMessage();
		e.setMessage(exception.getMessage());
		e.setCode(Status.UNAUTHORIZED.getStatusCode());
		e.setChallenges(exception.getChallenges());

		return Response.status(Status.UNAUTHORIZED).type("application/json").entity(e).build();
	}

}
